import { deleteRequest, getRequest, postRequest, putRequest } from '@/utils/request';
import { req } from "@/api/manage";
import { Student } from './Student';
import {
  getMockStudentData,
  mockAddStudent,
  mockEditStudent,
  mockDeleteStudent,
  mockFetchStudentDetail
} from './mockData';

// 是否使用Mock数据
const USE_MOCK_DATA = false;
const USE_REQ_FLAG = false;

interface StudentQueryParams {
  pageNumber: number;
  pageSize: number;
  studentNo?: string;
  name?: string;
  grade?: string;
}

// 获取学生列表
export const apiStudentFetchList = (params: StudentQueryParams) => {
  if (USE_MOCK_DATA) {
    return getMockStudentData(params.pageNumber, params.pageSize);
  }
  return getRequest('/api/anon/student', params);
};

// 添加学生
export const apiStudentAdd = (data: Partial<Student>) => {
  if (USE_MOCK_DATA) {
    return mockAddStudent(data);
  }
  return postRequest('/api/anon/student', data);
};

// 编辑学生
export const apiStudentEdit = (id: number, data: Partial<Student>) => {
  if (USE_MOCK_DATA) {
    return mockEditStudent(id, data);
  }
  return putRequest(`/api/anon/student/${id}`, data);
};

// 删除学生
export const apiStudentDelete = (id: number) => {
  if (USE_MOCK_DATA) {
    return mockDeleteStudent(id);
  }
  if (USE_REQ_FLAG) {
    return req.delById('/api/anon/student', id);
  }
  return deleteRequest(`/api/anon/student/${id}`);
};

// 获取学生详情
export const apiStudentFetchDetail = (id: number) => {
  if (USE_MOCK_DATA) {
    return mockFetchStudentDetail(id);
  }
  return getRequest(`/api/anon/student/${id}`);
};
